package com.common.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.common.domain.entity.Department;
import com.common.domain.entity.Problem;
import com.common.domain.entity.ResponseResult;
import com.common.domain.entity.Role;
import com.common.domain.vo.ProblemVo;
import com.common.mapper.DepartmentMapper;
import com.common.mapper.ProblemMapper;
import com.common.service.DepartmentService;
import com.common.service.ProblemService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.junit.platform.commons.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
* @author pc
* @description 针对表【sys_point】的数据库操作Service实现
* @createDate 2023-09-02 11:17:55
*/
@Service
public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Department>
implements DepartmentService {

    @Autowired
    private DepartmentMapper departmentService;

    @Override
    public ResponseResult allDepartmentList(Integer pageNum, Integer pageSize, String name) {
        PageHelper.startPage(pageNum,pageSize);

        LambdaQueryWrapper<Department> wrapper = new LambdaQueryWrapper();
        wrapper.like(!StringUtils.isBlank(name),Department::getDepartmentName,name);
        wrapper.orderByDesc(Department::getCreateTime);
        List<Department> list = departmentService.selectList(wrapper);
        PageInfo<Department> pageInfo = new PageInfo<>(list);
        pageInfo.setList(list);

        return ResponseResult.okResult(pageInfo);
    }



    @Override
    public ResponseResult deleteDepartment(String ids) {
        String[] split = ids.split(",");
        removeByIds(Arrays.asList(split));
        return ResponseResult.okResult();
    }

    @Override
    public ResponseResult insertDepartment(Department department) {
        save(department);
        return ResponseResult.okResult();
    }

    @Override
    public ResponseResult updateDepartment(Department department) {
        updateById(department);
        return ResponseResult.okResult();
    }


}
